package cn.yuanqiao.web.controller.archive.danganzhengli;

import cn.yuanqiao.archive.danganzhengli.domain.HandOverDa;
import cn.yuanqiao.archive.danganzhengli.domain.vo.HandOverDaVo;
import cn.yuanqiao.archive.danganzhengli.service.IHandOverDaService;
import cn.yuanqiao.common.core.domain.entity.SysDept;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zjj
 * @date 2023/7/21
 */
@RestController
@RequestMapping("/archive/yijiao")
public class HandOverDaController extends BaseController {

    @Autowired
    private IHandOverDaService handOverDaService;

    /**
     * 添加移交单中的档号
     * @return
     */
    @Log(title = "添加移交单中的档号", businessType = BusinessType.INSERT)
    @PostMapping("/addHandOverDa")
    @PreAuthorize("@ss.hasPermi('manage:yijiao:addHandOverDa')")
    public AjaxResult addHandOverDa(@RequestParam("categoryId") Long categoryId, @RequestParam("ids") Long [] ids){
        //添加移交单已最大门类为准
        String msg = handOverDaService.insertHandOverDa(categoryId,ids);
        return AjaxResult.success(msg);
    }

    /**
     * 删除移交单中档案
     * @return
     */
    @Log(title = "删除移交单中档案", businessType = BusinessType.DELETE)
    @PostMapping("/delHandOverDa")
    public AjaxResult delHandOverDa(@RequestParam("ids") Long [] ids){
        //添加移交单已最大门类为准
        String msg = handOverDaService.delHandOverDa(ids);
        return AjaxResult.success(msg);
    }

    @Log(title = "查询移交单中档案", businessType = BusinessType.SELECT)
    @PostMapping("/selectHandOverDaVo")
    public TableDataInfo selectHandOverDaVo(@RequestParam("categoryId") String categoryId){
        HandOverDa handOverDa = new HandOverDa();
        if(StringUtils.isNotEmpty(categoryId)){
            handOverDa.setCategoryId(Long.valueOf(categoryId));
        }else {
            throw new ServiceException("系统参数错误！");
        }
        List<HandOverDaVo> list = handOverDaService.selectHandOverDaVo(handOverDa);
        return getDataTable(list);
    }

    //获取立档单位
    @Log(title = "查询当前门类的立档单位", businessType = BusinessType.SELECT)
    @GetMapping("/selectDept/{categoryId}")
    public AjaxResult selectDept(@PathVariable("categoryId") String categoryId){
        if(StringUtils.isNotEmpty(categoryId)){
            SysDept dept=handOverDaService.selectDept(categoryId);
            return AjaxResult.success(dept);
        }else {
            throw new ServiceException("参数错误！");
        }

    }
    //
    //获取立档单位
    @Log(title = "判断是否有在线移交权限", businessType = BusinessType.SELECT)
    @GetMapping("/getAuthority")
    public AjaxResult getAuthority(){

      return AjaxResult.success(handOverDaService.getAuthority());
    }
}
